using System;
using UnityEngine;
using System.Collections;
public class PostPng
{
public static string UploadUrl = http://127.0.0.1/getpng.php;
public static void UploadPNG(MonoBehaviour thread, string fileName, Action<bool> result)
{
thread.StartCoroutine(UploadPNG(fileName, result));
}
private static IEnumerator UploadPNG(string fileName, Action<bool> result)
{
yield return new WaitForEndOfFrame();
int width = Screen.width;
int height = Screen.height;
Texture2D tex = new Texture2D(width, height, TextureFormat.RGB24, false);
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
tex.Apply();
byte[] bytes = tex.EncodeToPNG();
GameObject.Destroy(tex);
WWWForm form = new WWWForm();
form.AddField("enctype", "multipart/form-data");
form.AddBinaryData("PngUpload", bytes, fileName, "image/png");
WWW post = new WWW(UploadUrl , form);
yield return post;
if (string.IsNullOrEmpty(post.error) && result != null)
{
result(true);
}
else
{
result(false);
}
post.Dispose();
}
}